﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>login</title>

    <link rel="stylesheet" href="css/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/style.css">

</head>
<body>


<div class="materialContainer">
    <div class="box">
        <div class="title">登录</div>
        <form action="/login" method="POST">
            <div class="input">
                <label for="name">用户名</label>
                <input type="text" name="username" id="name">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="pass">密码</label>
                <input type="password" name="password" id="pass">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="code">验证码</label>
                <input type="code" name="code" id="code">
                <span class="spin"></span>
                <img alt="验证码" onclick="this.src='/kaptcha.jpg'" src="/kaptcha.jpg">
                <a>看不清？点击图片刷新一下</a>
            </div>
            <div class="button login">
                <button type="submit">
                    <span>登录</span>
                    <i class="fa fa-check"></i>
                </button>
            </div>
        </form>
        <a href="javascript:" class="pass-forgot">忘记密码？</a>
    </div>

    <div class="overbox">
        <div class="material-button alt-2">
            <span class="shape"></span>
        </div>
        <div class="title">注册</div>
        <div class="input">
            <label for="regname">用户名</label>
            <input type="text" name="regname" id="regname">
            <span class="spin"></span>
        </div>
        <div class="input">
            <label for="regpass">密码</label>
            <input type="password" name="regpass" id="regpass">
            <span class="spin"></span>
        </div>
        <div class="input">
            <label for="reregpass">确认密码</label>
            <input type="password" name="reregpass" id="reregpass">
            <span class="spin"></span>
        </div>
        <div class="button" id="register">
            <button>
                <span>注册</span>
            </button>
        </div>
    </div>

</div>

<script src="js/jquery.min.js"></script>
<script src="js/index.js"></script>
<script>
    $("#register").on('click',function(){
        let username = $("#regname").val();
        let password = $("#regpass").val();
        let qpassword = $("#reregpass").val();
        if (password != qpassword){
            alert("密码不一致");
        }
        console.log(username+" "+password);
        $.ajax({
            url: '/user/register',
            data: JSON.stringify({
                "userName": username,
                "password": password
            }),
            type: 'POST',
            dataType:"json",
            contentType:"application/json",
            success: function(res){
                console.log(res);
                if (res.code == "200"){
                    window.location.href='/login.html';
                }
            }
        })
    })

</script>
</body>
</html>